<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
</head>
<style>
    .aui-list .aui-list-item:after {
        width: 100%;
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: auto;
        right: auto;
        bottom: 0;
        left: 0;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-list:before {
        height: 1px;
        background-color: #dddddd;
        display: block;
        content: none;
        position: absolute;
        top: 0;
        left: 0;
        right: auto;
        bottom: auto;
        width: 100%;
        z-index: 2;
        -webkit-transform-origin: 50% 100%;
        transform-origin: 50% 100%;
        pointer-events: none;
    }

    .aui-card-list-header {
        color: #212121;
        font-size: 22px;
        font-weight: 600;
    }

    #pn1::after {
        content: "";
        width: 22px;
        height: 22px;
        float: left;
        margin: 0 220px 0 0;
        background: url(../image/pn1.png) no-repeat;
        background-size: 22px 22px;
    }

    #pn2::after {
        content: "";
        width: 22px;
        height: 22px;
        float: left;
        margin: 0 220px 0 0;
        background: url(../image/pn2.png) no-repeat;
        background-size: 22px 22px;
    }

    #pn3::after {
        content: "";
        width: 22px;
        height: 22px;
        float: left;
        margin: 0 220px 0 0;
        background: url(../image/pn3.png) no-repeat;
        background-size: 22px 22px;
    }

    .aui-mask {
        width: 100%;
        height: 100%;
        z-index: 999;
        display: block;
    }

    .aui-popup {
        position: fixed;
        background-color: #fff;
        border-radius: 5px;
        z-index: 1000;
        width: 80%;
    }

    .aui-popup-center {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }

    .aui-popup-header {
        padding: 10px 15px;
        border-bottom: 1px solid #eee;
        position: relative;
    }

    .aui-popup-header h3 {
        margin: 0;
        font-size: 16px;
    }

    .aui-popup-close {
        position: absolute;
        top: 10px;
        right: 15px;
        font-size: 20px;
        cursor: pointer;
    }

    .aui-popup-body {
        padding: 15px;
    }

    #cancelOrderReason {
        width: 100%;
        min-height: 100px;
        padding: 8px;
        border: 1px solid #ddd;
        border-radius: 4px;
        resize: vertical;
        box-sizing: border-box;
    }

    .aui-popup-footer {
        padding: 10px 15px;
        border-top: 1px solid #eee;
        text-align: right;
    }

    .aui-btn {
        padding: 5px 15px;
        border: 1px solid #ddd;
        border-radius: 4px;
        background: #fff;
        cursor: pointer;
    }

    .aui-btn-primary {
        background-color: #49A0E4;
        color: white;
        border-color: #49A0E4;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            待维修
        </div>
    </header>

    <div class="aui-card-list ui-selectee" style="margin-top:50px;">
        <div class="aui-card-list-header ui-selectee" id="pn1">
            设备信息
        </div>
        <div class="aui-card-list-content sortable ui-selectee ui-sortable" contenteditable="false">
            <div class="aui-card-list ui-selectee">
                <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                    <ul class="aui-list aui-form-list" style="content: none;">
                        <li class="aui-list-item" style="content: none;">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-label">设备编码</div>
                                <div class="aui-list-item-input">
                                    <input type="text" readonly id="equipCode" value="" />
                                </div>
                            </div>
                        </li>
                        <li class="aui-list-item">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-label" >设备名称</div>
                                <div class="aui-list-item-input">
                                    <input type="text" readonly id="equipName" value="" />
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="aui-card-list ui-selectee">
        <div class="aui-card-list-header ui-selectee" id="pn2"  > 故障信息 </div>
        <div class="aui-card-list-content sortable ui-selectee ui-sortable" contenteditable="false">
            <div class="aui-card-list-content sortable ui-selectee ui-sortable">
                <ul class="aui-list aui-form-list" style="content: none;">
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label ui-selectee"  >维修单号</div>
                            <div class="aui-list-item-input ui-selectee">
                                <input type="text" readonly id="faultOrderNo" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label ui-selectee"  >故障描述</div>
                            <div class="aui-list-item-input ui-selectee">
                                <input type="text" readonly id="description" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label ui-selectee"  >是否停机</div>
                            <div class="aui-list-item-input ui-selectee">
                                <input type="text" readonly id="ext15" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label ui-selectee"  contenteditable="false">报修人</div>
                            <div class="aui-list-item-input ui-selectee">
                                <input type="text" readonly id="ext06" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label ui-selectee"  contenteditable="false">联系方式</div>
                            <div class="aui-list-item-input ui-selectee">
                                <input type="text" readonly id="contact" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width: 45%;">报修时间</div>
                            <div class="aui-list-item-input">
                                <input type="text" readonly id="faultdate1" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width: 45%;">设备位置</div>
                            <div class="aui-list-item-input">
                                <input type="text" readonly id="faultlocation" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width: 45%;">维修人</div>
                            <div class="aui-list-item-input">
                                <input type="text" readonly id="ydPerson" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label" style="width: 45%;">维修班组</div>
                            <div class="aui-list-item-input">
                                <input type="text" readonly id="ydPersonTeam" value="" />
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label">紧急程度</div>
                            <div class="aui-list-item-input">
                                <input type="text" readonly id="ext16" value="" />
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 撤单原因弹窗 -->

        <div id="cancelOrderReasonPopup"
            style="border: 1px solid black; background-color: #fff;width:98%;position: fixed;transform: translate(1%, -200%);z-index: 1000">
            <div>
                <div>
                    <textarea style="width:95%;margin-left: 6px;margin-top: 10px;" id="cancelOrderReason"
                        placeholder="请填写撤单原因"></textarea>
                </div>
                <div style=" background-color: #fff;">
                    <button style="margin-left: 50%;" class="aui-btn" onclick="hideCancelOrderReasonPopup()">取消</button>
                    <button class="aui-btn aui-btn-primary" onclick="confirmCancelOrder()">确定</button>
                </div>
            </div>
        </div>

    </div>




    <footer class="aui-bar aui-bar-tab ui-selectee" style="color: #f5f5f5;">
        <div class="aui-bar aui-bar-btn aui-bar-btn-full ui-selectee" style="min-height: 2.8rem;font-size: 1.0rem;">
            <div class="aui-bar-btn-item aui-active ui-selectee"
                style="border-color: #f5f5f5;background-color: #49A0E4;" onclick="showCancelOrderReasonPopup()">撤单</div>
            <div class="aui-bar-btn-item aui-active ui-selectee"
                style="border-color: #f5f5f5;background-color: #49A0E4;" onclick="goPageDetail('emEquipmentDispatchWork')">变更维修人</div>
            <div class="aui-bar-btn-item aui-active ui-selectee"
                style="border-color: #f5f5f5;background-color: #49A0E4;"
                onclick="goPageDetail('emequipmentfaltRepaire')">开始维修</div>
        </div>
    </footer>


    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/public.js"></script>
    <script type="text/javascript" src="../script/isDialog.js"></script>

    <script type="text/javascript">
        // 返回按钮
        function closeWin() {
            api.closeWin({});
        }

        apiready = function () {
            getEmequipmentfaultDataInfo(api.pageParam.sysid);
            document.getElementById("cancelOrderReasonPopup").style.display = "none";
        }

        // 获取信息
        function getEmequipmentfaultDataInfo(sysid) {
            var un = localStorage.getItem('un');
            var serverUrl = localStorage.getItem('serverUrl');
            var url = serverUrl + "/app/getEquipmentFaultList";
            var data = {
                values: {
                    sysid: sysid,
                    un: un
                }
            };

            api.ajax({
                url: url,
                method: 'post',
                dataType: 'json',
                timeout: 30,
                returnAll: false,
                data: data
            }, function (ret, err) {
                if (ret) {
                    var data = JSON.stringify(ret);
                    var myobj = eval("(" + data + ")");

                    if (myobj.code == "0") {
                        var list = eval(myobj.list);
                        var entity = list[0];
                        $("#equipCode").val(entity.equipCode);
                        $("#equipName").val(entity.equipName);
                        $("#faultOrderNo").val(entity.faultOrderNo);
                        $("#description").val(entity.description);
                        $("#ext15").val(entity.ext15);
                        $("#ext06").val(entity.ext06);
                        $("#contact").val(entity.contact);
                        $("#faultdate1").val(entity.faultdate);
                        $("#faultlocation").val(entity.ext09);
                        $("#ydPerson").val(entity.ydPerson);
                        $("#ydPersonTeam").val(entity.ydPersonTeam);
                        $("#ext16").val(entity.ext16);
                    } else if (myobj.code == "1") {
                        $api.html($api.byId("tbodyHtml"), "");
                        api.toast({
                            msg: myobj.message,
                            duration: 3000
                        });
                    }
                }
            });
        }

        // 状态设置
        function setStatus(sta) {
            var un = localStorage.getItem('un');
            var serverUrl = localStorage.getItem('serverUrl');
            var url = serverUrl + "/app/setEmequipmentfaultDataAppStatus";
            var data = {
                values: {
                    sysid: api.pageParam.sysid,
                    ext01: sta,
                    un: un
                }
            };

            api.ajax({
                url: url,
                method: 'post',
                dataType: 'json',
                timeout: 30,
                returnAll: false,
                data: data
            }, function (ret, err) {
                if (ret) {
                    var data = JSON.stringify(ret);
                    var myobj = eval("(" + data + ")");

                    if (myobj.code == "0") {
                        api.hideProgress();
                        api.toast({
                            msg: "保存成功",
                            duration: 3000
                        });
                        api.openWin({
                            name: "emequipmentfaltToExecuted",
                            url: "emequipmentfaltToExecuted.html",
                        });
                    } else if (myobj.code == "1") {
                        api.toast({
                            msg: myobj.message,
                            duration: 3000
                        });
                    }
                }
            });
        }

        // 撤单弹窗控制
        function showCancelOrderReasonPopup() {
            document.getElementById("cancelOrderReasonPopup").style.display = "block";
        }

        function hideCancelOrderReasonPopup() {
            document.getElementById("cancelOrderReasonPopup").style.display = "none";
        }

        function confirmCancelOrder() {
            var reason = document.getElementById("cancelOrderReason").value.trim();
            if (reason === "") {
                api.toast({
                    msg: "请填写撤单原因",
                    duration: 3000
                });
                return;
            }
            setStatusWithReason("2", reason);
            hideCancelOrderReasonPopup();
        }

        function setStatusWithReason(sta, reason) {
            var un = localStorage.getItem('un');
            var serverUrl = localStorage.getItem('serverUrl');
            var url = serverUrl + "/app/getEquipmentFaultCX";
            var data = {
                values: {
                    sysid: api.pageParam.sysid,
                    status: sta,
                    un: un,
                    cancelReason: reason
                }
            };

            api.ajax({
                url: url,
                method: 'post',
                dataType: 'json',
                timeout: 30,
                returnAll: false,
                data: data
            }, function (ret, err) {
                if (ret) {
                    var data = JSON.stringify(ret);
                    var myobj = eval("(" + data + ")");

                    if (myobj.code == "0") {
                        api.hideProgress();
                        api.toast({
                            msg: "撤单成功",
                            duration: 3000
                        });
                        api.openWin({
                            name: 'emequipmentfaultRepaireList',
                            url: 'emequipmentfaultRepaireList.html',
                            reload: true,
                        });
                    } else if (myobj.code == "1") {
                        api.toast({
                            msg: myobj.message,
                            duration: 3000
                        });
                    }
                }
            });
        }

        //开始维修
        function emRepaireStart() {
            //设备故障主键
            var sysid = api.pageParam.sysid;

            api.showProgress({
                title: '保存中...',
            });
            var un = localStorage.getItem('un'); //登录用户
            var serverUrl = localStorage.getItem('serverUrl');
            var url = serverUrl + "/app/emRepaireStart";
            var data = {
                values: { ////以表单方式提交参数（JSON对象）
                    un: un, //登录用户
                    sysid: sysid, //设备故障主键
                }
            };
            api.ajax({
                url: url,
                method: 'post',
                dataType: 'json',
                timeout: 30,
                returnAll: false,
                data: data
            }, function (ret, err) {
                if (ret) {
                    var data = JSON.stringify(ret);
                    var myobj = eval("(" + data + ")");
                    //成功
                    if (myobj.code == '0') {
                        api.hideProgress();
                        api.toast({
                            msg: "操作成功",
                            duration: 3000
                        });
                    } else if (myobj.code == '1') {
                        api.hideProgress();
                        api.toast({
                            msg: myobj.message,
                            duration: 3000
                        });
                    }
                }
            });
        }

        //跳转详情页面
        function goPageDetail(name) {
            //开始维修保存过程表
            if (name == 'emequipmentfaltRepaire') {
                emRepaireStart()
            }
            //打开页面
            api.openWin({
                name: name,
                url: name + '.html',
                pageParam: {
                    sysid: api.pageParam.sysid
                },
            });
        }
    </script>
</body>

</html>